{include file='fcworker/fc_head'}
{include file='fcworker/fc_headsearch'}
<style>
    .label{
        padding: 4px 3px;
        border-radius: 3px;
        color: #FFFFFF;
    }
    .label-success{
        background: #2a8bee;
    }
    .label-danger{
        background: red;
    }
</style>
<div id="mescroll" class="mescroll">
    <div id="app">
        <div class="container">
            <div class="numPeople">
                <ul>
                    {loop $status_arr $row}
                    <li><a href="{php echo '/'.createMobileUrl("X_beCoupon",array("themeid"=>$themeid));}&status={$row['status']}"><p>{$row['title']}</p><span>{$row['total']}</span></a></li>
                    {/loop}
                </ul>
            </div>
        </div>
        <div class="activeBox" >
            <div class="activeInfor activeTab fixed_t_w " style="{if $sj_list}top: 2.9rem{else}top: 2rem{/if}">

                <table cellpadding="0" cellspacing="0" width="100%" id="list">
                    <tr style="height: 40px;">
                        <th style="width:.7rem;">序号</th>
                        <th style="width:.7rem;">头像</th>
                        <th style="width:1.7rem;">用户信息</th>
                        <th style="width:1.2rem;">优惠券</th>
                        <th style="width:1.2rem;">状态</th>
                        <th style="width:1.4rem;">更新时间</th>


                    </tr>
                    {loop $list $key $item}
                    <tr class="new_tr" >
                    <td>{php echo $key+1;}</td>
                    <td><img src="{$item['avatar']}" class="td-img"></td>
                    <td>{$item['username']}<br>{$item['mobile']}</td>
                    <td>{$item['name']}</td>
                    {if $item['status']==2}
                    <td ><span class="label label-success">已使用</span></td>
                    {else}
                    <td ><span class="label label-danger" >未使用</span></td>
                    {/if}
                    <td>{if $item['status']==2}{$item['updated_at']}{/if}</td>
                    </tr>
                    {/loop}
                </table>
                <div style="height: 60px;width: 100%">
                    {if $hasNext}
                    <p style="text-align: center;font-size: 12px;color: gray;" class="tips_p">加载更多..</p>
                    {/if}
                </div>
            </div>
        </div>

        <input type="hidden" name="themeid" id="themeid" value="{$themeid}">
        <input type="hidden" name="page" id="page" value="{$page}">
        <input type="hidden" name="hasNext" id="hasNext" value="{$hasNext}">
        <input type="hidden" name="tuannum" id="tuannum" value="{$tuannum}">
        {include file='fcworker/fc_foot_yixuan'}
        <div class="h110"></div>

    </div>
</div>
{include file='fcworker/fc_foot'}
</body>
<!--  下拉刷新-->
<script>
    const mescroll = new MeScroll("mescroll", {
        down: {
            auto: false,
            callback: () => {
                mescroll.endSuccess();
                setTimeout(() => {
                    window.location.reload();
                },500)
            }
        },
        up: {
            use: true,
            auto: false,
            isBounce: false,
            callback: (page) => {
                let pageNum = page.num+1;
                let scan = $("#scan").val();
                var p_id = $("#p_id").val();
                let op = $("#op").val();
                var themeid = $("#themeid").val();
                var tuannum = $("#tuannum").val();
                let postUrl="/{php echo createMobileUrl('X_beCoupon',array('themeid'=>$themeid));}";
                $.ajax({
                    url:postUrl,
                    dataType:'json',
                    method:'post',
                    data: {page:pageNum,p_id:p_id},
                    success:function (e) {
                        let data = e.data;
                        let error = e.error;
                        let msg = e.msg;
                        let curPageData = data.list; // 接口返回的当前页数据列表
                        if (error!=0){
                            layer.msg(msg);
                        }else{
                            if (data.list){
                                $("#list").append(curPageData);
                            }
                            // layer.closeAll();
                        }
                        // loadingState = false;
                        if (data.hasNext){
                            hasNext = 1;
                        }else{
                            hasNext = 0;
                        }
                        $("#hasNext").val(hasNext);
                        mescroll.endSuccess(curPageData.length, hasNext);
                    },
                    fail:function (err) {
                        console.log(err)
                    }
                });
            }
        }
    })
    let id = {php echo empty($_P['id']) ? 'null': GPC['id'];};
    if(!$("#hasNext").val() ) {
        mescroll.lockUpScroll(true);
    }
    if(id) {
        mescroll.lockUpScroll(true);
    }
</script>
<script>
    var loadingState= false;
    var hasNext = 1;
        $(".fixed_t_w").scroll(function(){
        hasNext = $("#hasNext").val();
        var height = $(".fixed_t_w").height();

        var scrollSpace = $(".fixed_t_w").scrollTop();

        if (scrollSpace > $(".fixed_t_w table").height() - height){
            if (!loadingState && hasNext==1){
                var page = $("#page").val();
                var p_id = $("#p_id").val();
                var searchtxt = $("#searchtxt").val();
                var next_page = +page+1;
                loadingState = true;
                $("#page").val(next_page);
                layer.msg('加载中', {
                    icon: 16
                    ,shade: 0.01
                });
                var postUrl="/{php echo createMobileUrl('X_beCoupon',array('themeid'=>$themeid));}";
                $.ajax({
                    url:postUrl,
                    dataType:'json',
                    method:'post',
                    data: {page:next_page,p_id:p_id,searchtxt:searchtxt},
                    success:function (e) {
                        let data = e.data;
                        let error = e.error;
                        let msg = e.msg;
                        if (error!=0){
                            layer.msg(msg);
                        }else{
                            if (data.list){
                                $("#list").append(data.list);
                            }
                            layer.closeAll();
                        }
                        loadingState = false;
                        if (data.hasNext){
                            hasNext = 1;
                        }else{
                            hasNext = 0;
                            $(".tips_p").html('暂无更多数据！');
                        }
                        $("#hasNext").val(hasNext);
                    },
                    fail:function (err) {
                        console.log(err)
                    }
                });
            }
        }
    });

        $('.contBtn').click(function(){
            if($(this).hasClass('on')){
                $(this).parent().siblings('.information').removeClass('cur');
                $(this).removeClass('on')
            }else{
                $(this).addClass('on')
                $(this).parent().siblings('.information').addClass('cur');
            }
        })
        $('.backTop').click(function(){
            $('body,html').animate({scrollTop:0},500);
        })
        $(function () {
            $("#newsList").on('click','.teamTit',function () {
                var id = this.dataset.id;
                var jump_url ='{php echo "/".createMobileUrl("X_order",array("themeid"=>$themeid));}'+'&id='+id;
                self.location.href=jump_url;
            });
        });
</script>
</html>
